package com.moyun.finance.controller;

import com.moyun.finance.entity.Bill;
import com.moyun.finance.entity.Contract;
import com.moyun.finance.entity.Response;
import com.moyun.finance.service.BillService;
import com.moyun.finance.service.ContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/bill")
public class BillController {
    @Autowired
    BillService bs;

    //流水新增
    @RequestMapping("/save")
    public @ResponseBody Response save(@RequestBody Bill b){
        Response res = bs.save(b);
        return res;
    }

    //流水修改
    @RequestMapping("/update")
    public @ResponseBody Response update(@RequestBody Bill b){
        Response res = bs.update(b);
        return res;
    }

    //流水删除
    @RequestMapping("/delete")
    public @ResponseBody Response delete(@RequestBody Bill b){
        Response res = bs.delete(b);
        return res;
    }

    //查询指定公司所有流水
    @RequestMapping("/findAllByCompanyId")
    public @ResponseBody Response findAllByCompanyId(String companyId){
        List<Bill> bills = bs.findAll(companyId);
        return new Response("",bills,true);
    }

    //根据id查流水
    @RequestMapping("/findById")
    public @ResponseBody Response findOneById(String billId){
        Bill b = bs.findOneById(billId);
        return new Response("",b,true);
    }

    //获取账户下的流水列表
    @RequestMapping("/findByAccount")
    public @ResponseBody Response findByAccount(String accountId){
        List<Bill> bills = bs.findByAccount(accountId);
        return new Response("",bills,true);
    }
}
